package com.alibaba.algo.components.yapi.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Description: java类型转换yapi平台类型
 * @author: malin
 * @date: 2020-12-3 11:15:45
 */
public class TypeConverter {

	public static String getYapiType(String javaType) {
		if (javaType.equals("java.lang.String")) {
			return "string";
		} else if (javaType.equals("java.lang.Integer") || javaType.equals("int") || javaType.equals("long") || javaType.equals("java.lang.Long")) {
			return "integer";
		} else if (javaType.startsWith("java.util.List") || javaType.startsWith("java.util.Set")) {
			return "array";
		} else if (javaType.startsWith("java.util.Map")) {
			return "object";
		} else if (javaType.equals("java.lang.Boolean") || javaType.equals("boolean")) {
			return "boolean";
		} else if (javaType.equals("java.util.Date") || javaType.equals("java.time.LocalDateTime") ) {
			return "string";
		} 
		return "object";
	}

	public static boolean isNumericzidai(String str) {
		Pattern pattern = Pattern.compile("-?[0-9]+(\\.[0-9]+)?");
		Matcher isNum = pattern.matcher(str);
		if (!isNum.matches()) {
			return false;
		}
		return true;
	}

	public static void main(String[] args) {
		System.out.println(isNumericzidai("-232.321"));
	}
}
